// 服务端动态路由示例
// 这个文件展示了服务端应该返回的动态路由格式

/**
 * 服务端应该在登录接口或获取用户信息接口中返回 dynamicRoutes 字段
 * 
 * 响应格式：
 * {
 *   code: 200,
 *   data: {
 *     userInfo: {
 *       id: 1,
 *       username: "admin",
 *       dynamicRoutes: [ ... ]  // 动态路由数组
 *     }
 *   }
 * }
 */

// 示例1：管理员的动态路由（拥有所有权限）
export const adminDynamicRoutes = [
  // 系统管理
  {
    path: "/system",
    title: "系统管理",
    icon: "setting",
    component: "system/index",
    children: [
      {
        path: "/system/user",
        title: "用户管理",
        icon: "user",
        component: "system/user/index"
      },
      {
        path: "/system/role",
        title: "角色管理",
        icon: "postcard",
        component: "system/role/index"
      },
      {
        path: "/system/permission",
        title: "权限管理",
        icon: "key",
        component: "system/permission/index"
      }
    ]
  },
  // 内容管理
  {
    path: "/content",
    title: "内容管理",
    icon: "document",
    component: "content/index",
    children: [
      {
        path: "/content/article",
        title: "文章管理",
        icon: "edit",
        component: "content/article/index"
      },
      {
        path: "/content/category",
        title: "分类管理",
        icon: "folder",
        component: "content/category/index"
      },
      {
        path: "/content/tag",
        title: "标签管理",
        icon: "collection-tag",
        component: "content/tag/index"
      }
    ]
  },
  // 产品管理
  {
    path: "/product",
    title: "产品管理",
    icon: "goods",
    component: "product/index"
  },
  // 关于页面
  {
    path: "/about",
    title: "关于",
    icon: "info-filled",
    component: "about/index"
  }
];

// 示例2：普通用户的动态路由（只有部分权限）
export const userDynamicRoutes = [
  // 只能看到内容管理的文章
  {
    path: "/content/article",
    title: "文章管理",
    icon: "edit",
    component: "content/article/index"
  },
  // 只能看到产品列表
  {
    path: "/product",
    title: "产品管理",
    icon: "goods",
    component: "product/index"
  }
];

// 示例3：访客的动态路由（最少权限）
export const guestDynamicRoutes = [
  {
    path: "/about",
    title: "关于",
    icon: "info-filled",
    component: "about/index"
  }
];

// 示例4：带有自定义meta的动态路由
export const customMetaDynamicRoutes = [
  {
    path: "/important",
    title: "重要页面",
    icon: "star",
    component: "important/index",
    meta: {
      sort: 1,  // 排序，数字越小越靠前
      hidden: false  // 是否隐藏
    }
  },
  {
    path: "/hidden-page",
    title: "隐藏页面",
    icon: "view",
    component: "hidden/index",
    meta: {
      hidden: true  // 这个页面不会在菜单中显示
    }
  }
];

/**
 * 如何在开发环境使用这些示例数据？
 * 
 * 方法1：在 user.js store 中直接使用
 * 
 * import { adminDynamicRoutes } from './mock-dynamic-routes.example';
 * 
 * const getUserInfo = async () => {
 *   // 开发环境使用 mock 数据
 *   if (import.meta.env.DEV) {
 *     dynamicRoutes.value = adminDynamicRoutes;
 *     return;
 *   }
 *   
 *   // 生产环境调用真实接口
 *   const response = await userApi.getUserInfo();
 *   dynamicRoutes.value = response.data.dynamicRoutes || [];
 * };
 * 
 * 方法2：在 api/user.js 中 mock 接口返回
 * 
 * import { adminDynamicRoutes } from '@/store/mock-dynamic-routes.example';
 * 
 * export const userApi = {
 *   async getUserInfo() {
 *     // 开发环境返回 mock 数据
 *     if (import.meta.env.DEV) {
 *       return {
 *         data: {
 *           id: 1,
 *           username: "admin",
 *           dynamicRoutes: adminDynamicRoutes
 *         }
 *       };
 *     }
 *     
 *     // 生产环境调用真实接口
 *     return request.get('/api/user/info');
 *   }
 * };
 */

/**
 * 服务端实现参考（Node.js + Express）
 * 
 * app.get('/api/user/info', async (req, res) => {
 *   const user = await getUserFromToken(req.headers.authorization);
 *   
 *   // 根据用户角色返回不同的动态路由
 *   let dynamicRoutes = [];
 *   
 *   if (user.role === 'admin') {
 *     dynamicRoutes = [
 *       {
 *         path: "/system",
 *         title: "系统管理",
 *         icon: "setting",
 *         component: "system/index",
 *         children: [...]
 *       },
 *       // ... 更多路由
 *     ];
 *   } else if (user.role === 'user') {
 *     dynamicRoutes = [
 *       {
 *         path: "/content/article",
 *         title: "文章管理",
 *         icon: "edit",
 *         component: "content/article/index"
 *       }
 *     ];
 *   }
 *   
 *   res.json({
 *     code: 200,
 *     data: {
 *       id: user.id,
 *       username: user.username,
 *       dynamicRoutes: dynamicRoutes
 *     }
 *   });
 * });
 */

